package com.authcode.controller;

import com.authcode.service.AuthExeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 类描述:
 *
 * @author jianweiwang
 * @version v1.0
 * @link wjw@choicesoft.com.cn
 * @date 2019/4/1 14:28
 **/
@Controller
@RequestMapping("/")
public class AuthExeController {

    @Autowired
    private AuthExeService authExeService;

    @RequestMapping("/execute")
    public void execute(@RequestParam("demandName") String demandName,
                        @RequestParam("demandUser") String demandUser,
                        @RequestParam("file") MultipartFile file,
                        HttpServletResponse response) throws IOException {
        authExeService.execute(file, response, demandName, demandUser);
    }

    @RequestMapping("/download")
    public void download(HttpServletResponse response) throws IOException {
        authExeService.download(response);
    }

    @RequestMapping("/success")
    public String success() {
        return "success";
    }

    @RequestMapping("/open")
    public void openFile(HttpServletResponse response) throws IOException {
        authExeService.openFile(response);
    }

    @RequestMapping("/export")
    public void export(HttpServletResponse response) throws Exception {
        authExeService.export(response);
    }
}
